package br.com.massai.model.dao;

import java.util.List;

import javax.ejb.Stateless;

import br.com.massai.model.entity.Action;
import br.com.massai.model.entity.Function;
import br.com.massai.model.exceptions.ErrorCore;
import br.com.massai.model.exceptions.SystemException;

@Stateless
public class ActionDAO extends GenericDAO<Action> implements ActionRepository {

	private static final long serialVersionUID = -1652208986376774051L;
	
	public ActionDAO(){
		super(Action.class);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Action> getActionsByFunction(Function function) throws SystemException {
		try{
			String query = "SELECT a FROM Action a WHERE a.function =:function";
			return em.createQuery(query).setParameter("function", function).getResultList();

		} catch (Exception e) {
			throw new SystemException(ErrorCore.ERROR_UNEXPECTED, e);
		}
	}
}